package com.byapp.fast.common.converter;


import com.byapp.fast.common.enums.PlayIdEnum;
import com.byapp.fast.modules.match.dto.MatchMsgEventDTO;
import com.byapp.fast.modules.match.entity.MatchOddsEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

public class MatchMsgEventDTOConverter {

    public static void create(MatchMsgEventDTO matchMsgEventDTO, MatchOddsEntity matchOddsEntity) {
        BeanUtils.copyProperties(matchMsgEventDTO, matchOddsEntity);
        String playId = matchMsgEventDTO.getPlayId();
        String odds = matchMsgEventDTO.getOdds();
        if (StringUtils.isNotEmpty(odds) && StringUtils.isNotEmpty(playId)) {
            // 根据PlayId设置赔率
            String[] oddStr = odds.split(",");
            // 亚盘
            if (StringUtils.equals(PlayIdEnum.GLOBAL_ASIAN.getCode().toString(), playId)
                    || StringUtils.equals(PlayIdEnum.HALF_ASIAN.getCode().toString(), playId)) {
                double win = Double.parseDouble(oddStr[0]);
                double lost = Double.parseDouble(oddStr[1]);
                matchOddsEntity.setWin(String.format("%.2f", win));
                matchOddsEntity.setLost(String.format("%.2f", lost));
            }
            // 欧盘
            if (StringUtils.equals(PlayIdEnum.GLOBAL_EUROPE.getCode().toString(), playId)
                    || StringUtils.equals(PlayIdEnum.HALF_EUROPE.getCode().toString(), playId)) {
                double win = Double.parseDouble(oddStr[0]);
                double even = Double.parseDouble(oddStr[1]);
                double lost = Double.parseDouble(oddStr[2]);
                matchOddsEntity.setWin(String.format("%.2f", win));
                matchOddsEntity.setEven(String.format("%.2f", even));
                matchOddsEntity.setLost(String.format("%.2f", lost));
            }
        }
    }
}
